
//
// OpenAjax Alliance Rules 
  // Rule group: Link Rules

//
with (OpenAjax.a11y) {
  addRules([
           
    // ------------------------
    // Rule 34: Link text should be as least four 4 characters long.
    // Group 11: Link Rule
    // 
    // Last update: 2011-03-31
    // ------------------------
	          
     {
      id            : 'RULE_34', 
      lastUpdated   : '2011-03-31', 
      messageCode   : 'MESSAGE_34',
      groupCode     : 'GROUP_11',
      context       : 'a', 
      language      : ['en-us','en-br',], 
      validateParams: { 
        min_text_length: { value: 3, type: 'Integer' },
      }, 
      dependencies  : [],
      validate      : function (ruleContext) {
      
        var MIN_TEXT_LENGTH = praseInt(this.validateParams.min_text_length.value);
      
        // Check to see if the ruleContext is from the cache
        if( ruleContext.accessible_text ) {
          var passed =  ruleContext.accessible_text.length > MIN_TEXT_LENGTH; 
          var node = ruleContext.node;      
        } else {
        // check to see if the ruleContext is lomger than the minimum length      
          var passed = util.getNodeTextRecursively(ruleContext).length > MIN_TEXT_LENGTH; 
          var node = ruleContext;
      } // endif

      return new ValidationResult(passed, [node], [], '', []); 

}  // endfunction


      },
           
    // ------------------------
    // Rule 35: Links with the same HREF should have the same link text.
    // Group 11: Link Rule
    // 
    // Last update: 2011-03-31
    // ------------------------
	          
     {
      id            : 'RULE_35', 
      lastUpdated   : '2011-03-31', 
      messageCode   : 'MESSAGE_35',
      groupCode     : 'GROUP_11',
      context       : 'document', 
      language      : [],
      validateParams: {},
      dependencies  : [],
      validate      : function (ruleContext) {

      var passed = true;
      var retArray = [];
      var length = OpenAjax.a11y.cache.links.length;
      
      OpenAjax.a11y.cache.sortLinkCache('href');
      
      for(var i = 1; i < length; i++ ) {
        if( OpenAjax.a11y.cache.links[i-1] == OpenAjax.a11y.cache.links[i] ) {
          
          retArray.push(OpenAjax.a11y.cache.links[i].node); 
          passed = false;
        } // endif
      } // endfor
            
    
  return new ValidationResult(passed, retArray, '', '', []); 
} // endfunction


      },
           
    // ------------------------
    // Rule 36: Links that point to different HREFs should have different link text.
    // Group 11: Link Rule
    // 
    // Last update: 2011-03-31
    // ------------------------
	          
     {
      id            : 'RULE_36', 
      lastUpdated   : '2011-03-31', 
      messageCode   : 'MESSAGE_36',
      groupCode     : 'GROUP_11',
      context       : 'document', 
      language      : [],
      validateParams: {},
      dependencies  : [],
      validate      : function (ruleContext) { 

  var passed = true; 
  var loadArray = new Array(); 
  var retArray = new Array(); 
  
  for (var j = 0; j < ruleContext.links.length; j++) { 
  
    var link4Cmp = ruleContext.links[j].href.toLowerCase(); 
    link4Cmp = link4Cmp.replace(/default.[a-z]*|index.[a-z]*/,''); 
    
    var obj = { 
      node: ruleContext.links[j], 
      text: util.getNodeTextRecursively(ruleContext.links[j]).toLowerCase(), 
      link4Cmp: link4Cmp
    }; // endobj 
    
    loadArray[loadArray.length] = obj; 
    
  } // endfor
    
  for (var j = 0; j < loadArray.length; j++) { 
    for (var k = j + 1; k < loadArray.length; k++) { 
      if (loadArray[j].text == loadArray[k].text && loadArray[j].link4Cmp != loadArray[k].link4Cmp) { 
        loadArray[j].sameLinkdiffURL = true; loadArray[k].sameLinkdiffURL = true; 
        passed = false; 
      } // endif
    } // endfor
    
    for (var j = 0; j < loadArray.length; j++) { 
      if (loadArray[j].sameLinkdiffURL) { 
        retArray.push(loadArray[j]); 
      } // endif
    } // endfor
      
  } // endfor
    
  return new ValidationResult(passed, retArray, '', '', []); 
    
}  // endfunction


      },
  ]); 
   }


        

